/*
	problem : 假日旅馆
	author  : 唐巧 北京师范大学
	ID		: 03001032
	Date    : 2006.10.10 AM
  
*/
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

typedef struct
{
	int dis, cost;
	bool choose;
}Thotel;

int n;
Thotel hotel[10010];

bool comp(Thotel a, Thotel b)
{
	return a.dis < b.dis;
}
bool comp2(Thotel a, Thotel b)
{
	return a.cost < b.cost;
}

int main()
{
	int i, mincost, mindis;
	int ans;

//	freopen("b.in", "r", stdin);

	while (scanf("%d", &n), n)
	{
		for (i=0; i<n; ++i)
		{
			scanf("%d%d", &hotel[i].dis, &hotel[i].cost);
			hotel[i].choose = false;
		}
		sort(hotel, hotel+n, comp);
		/*/ debug
		for (i=0; i<n; ++i)
			printf("No.%d: %d %d\n", i, hotel[i].dis, hotel[i].cost);
		*/
		mincost=hotel[0].cost+1;
		for (i=0; i<n; ++i)
		{
			if (hotel[i].cost<mincost)
			{
				mincost = hotel[i].cost;
				hotel[i].choose = true;
			}
		}

		sort(hotel, hotel+n, comp2);
		/*/ debug
		for (i=0; i<n; ++i)
			printf("No.%d: %d %d\n", i, hotel[i].dis, hotel[i].cost);
		*/
		ans = 0;
		mindis=hotel[0].dis+1;
		for (i=0; i<n; ++i)
		{
			if (hotel[i].dis < mindis)
			{
				mindis = hotel[i].dis;
				if (hotel[i].choose == true) ans++;
			}
		}
		printf("%d\n", ans);
		
	}

	return 0;
}